package com.zq.product.controller;

import com.github.pagehelper.PageInfo;
import com.zq.common.util.Result;
import com.zq.product.dao.dto.ProductSkuDto;
import com.zq.product.dao.entity.ProductSku;
import com.zq.product.dao.vo.ProductItemVo;
import com.zq.product.service.IProductSkuService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 张乔
 * @Date 2025/2/27 13:56
 */
@RestController
@RequestMapping("/product/productSku")
public class ProductSkuController {


    @GetMapping("getHello/{id}")
    public String getHello(@PathVariable("id") Long id) {
        System.out.println("hello是---------------------------"+id);
        return "Hellognfdkghjdfghjl";
    }

    @Resource
    private IProductSkuService productSkuService;

    //畅销商品，
    @GetMapping("/boom/productTen")
    public Result<Object> boomProductTen() {
        List<ProductSku> list=productSkuService.boomProductTen();
        return Result.successData(list);
    }

    //商品的详情，根据skuId获取
    @GetMapping("/detail/skuId")
    public Result<Object> detail(@RequestParam("skuId") String id) {
        long aLong = Long.parseLong(id);
        ProductItemVo productItemVo=productSkuService.detail(aLong);
        return Result.successData(productItemVo);
    }


//    根据商品的skuId查询商品
    @GetMapping("/getBySkuId/{id}")
    public  Result<Object> getBySkuId(@PathVariable("id") Long id){
        ProductSku productSku=productSkuService.getById(id);
        return Result.successData(productSku);
    }



//    获取所有商品
    @GetMapping("/getProductList")
    public Result<Object> getProductList() {
        List<ProductSku> list=productSkuService.getProductList();
        return Result.successData(list);
    }

//分页查询商品
    @GetMapping("/getProductListByPage/{page}/{limit}")
    public Result<Object> getProductListByPage(@PathVariable("page") Integer page,
                                               @PathVariable("limit") Integer limit) {
      PageInfo<ProductSku> list=productSkuService.getProductListByPage(page,limit);
        return Result.successData(list);

    }

//    根据商品名称查询商品
    @PostMapping("/getProductListBy")
    public Result<Object> getProductListBy(@RequestBody ProductSkuDto productSkuDto){
        List<ProductSku> list=    productSkuService.getProductListBy(productSkuDto);
return Result.successData(list);
    }






}
